

document.addEventListener('DOMContentLoaded', function () {
    // 路由映射  
    const routes = {
        '#home': function () {
            document.getElementById('content').innerHTML = '<h1>Home Page</h1>';
        },
        '#about': function () {
            document.getElementById('content').innerHTML = '<h1>About Us</h1><p>This is the about page.</p>';
        },
        '#contact': function () {
            document.getElementById('content').innerHTML = '<h1>Contact Us</h1><p>Please use the form below to contact us.</p>';
        }
    };

    // 监听hash变化  
    window.addEventListener('hashchange', function () {
        const route = window.location.hash;
        if (routes[route]) {
            routes[route]();
        } else {
            // 处理未定义的路由  
            document.getElementById('content').innerHTML = '<h1>404 Not Found</h1>';
        }
    });

    // 初始化当前路由  
    window.dispatchEvent(new HashChangeEvent('hashchange'));
});

